package com.miyake.dsp.osa.lab.wrapper;

import com.miyake.dsp.ComplexArray;
import com.miyake.dsp.osa.lab.Calculator;
import com.miyake.dsp.osa.lab.LabUiAnnotation;
import com.miyake.dsp.osa.lab.MathSetting2;
import com.miyake.dsp.osa.lab.MathSetting2.MathType;
@LabUiAnnotation(caption="Math")
public class MathWrapper extends Calculator {
	public static final String INPUT1 = "In #1";
	public static final String INPUT2 = "In #2";
	public static final String OUTPUT = "Output";
	private MathSetting2 setting;
	
	public MathWrapper(MathSetting2 setting) {
		this.setting = setting;
		initInput(INPUT1);
		initInput(INPUT2);
		initOutput(OUTPUT);
	}
	
	@Override
	public synchronized void process() {
		double[] in1 = this.getInput(INPUT1).getRealPart();
		double[] in2 = this.getInput(INPUT2).getRealPart();
		int length = Math.min(in1.length, in2.length);
		double[] out = new double[length];
		for (int i = 0; i < out.length; i++) {
			if (setting.getMathType().equals(MathType.PLUS)) {
				out[i] = in1[i] + in2[i];
			}
			else if (setting.getMathType().equals(MathType.MINUS)) {
				out[i] = in1[i] - in2[i];
			}
			else if (setting.getMathType().equals(MathType.DIV)) {
				out[i] = in1[i] / in2[i];
			}
			else if (setting.getMathType().equals(MathType.TIMES)) {
				out[i] = in1[i] * in2[i];
			}
		}
		this.setOutput(OUTPUT, new ComplexArray(out));
	}

	@Override
	public Object getSetting() {
		return setting;
	}

}
